﻿using System;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x0200015C RID: 348
	public class FBBIKArmBending : MonoBehaviour
	{
		// Token: 0x060005C5 RID: 1477 RVA: 0x00019B30 File Offset: 0x00017F30
		private void LateUpdate()
		{
			if (this.ik == null)
			{
				return;
			}
			if (!this.initiated)
			{
				IKSolverFullBodyBiped solver = this.ik.solver;
				solver.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(solver.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostFBBIK));
				this.initiated = true;
			}
			if (this.ik.solver.leftHandEffector.target != null)
			{
				Vector3 left = Vector3.left;
				this.ik.solver.leftArmChain.bendConstraint.direction = this.ik.solver.leftHandEffector.target.rotation * left + this.ik.solver.leftHandEffector.target.rotation * this.bendDirectionOffsetLeft + this.ik.transform.rotation * this.characterSpaceBendOffsetLeft;
				this.ik.solver.leftArmChain.bendConstraint.weight = 1f;
			}
			if (this.ik.solver.rightHandEffector.target != null)
			{
				Vector3 right = Vector3.right;
				this.ik.solver.rightArmChain.bendConstraint.direction = this.ik.solver.rightHandEffector.target.rotation * right + this.ik.solver.rightHandEffector.target.rotation * this.bendDirectionOffsetRight + this.ik.transform.rotation * this.characterSpaceBendOffsetRight;
				this.ik.solver.rightArmChain.bendConstraint.weight = 1f;
			}
		}

		// Token: 0x060005C6 RID: 1478 RVA: 0x00019D20 File Offset: 0x00018120
		private void OnPostFBBIK()
		{
			if (this.ik == null)
			{
				return;
			}
			if (this.ik.solver.leftHandEffector.target != null)
			{
				this.ik.references.leftHand.rotation = this.ik.solver.leftHandEffector.target.rotation;
			}
			if (this.ik.solver.rightHandEffector.target != null)
			{
				this.ik.references.rightHand.rotation = this.ik.solver.rightHandEffector.target.rotation;
			}
		}

		// Token: 0x060005C7 RID: 1479 RVA: 0x00019DDD File Offset: 0x000181DD
		private void OnDestroy()
		{
			if (this.ik != null)
			{
				IKSolverFullBodyBiped solver = this.ik.solver;
				solver.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(solver.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostFBBIK));
			}
		}

		// Token: 0x040002C3 RID: 707
		public FullBodyBipedIK ik;

		// Token: 0x040002C4 RID: 708
		public Vector3 bendDirectionOffsetLeft;

		// Token: 0x040002C5 RID: 709
		public Vector3 bendDirectionOffsetRight;

		// Token: 0x040002C6 RID: 710
		public Vector3 characterSpaceBendOffsetLeft;

		// Token: 0x040002C7 RID: 711
		public Vector3 characterSpaceBendOffsetRight;

		// Token: 0x040002C8 RID: 712
		private Quaternion leftHandTargetRotation;

		// Token: 0x040002C9 RID: 713
		private Quaternion rightHandTargetRotation;

		// Token: 0x040002CA RID: 714
		private bool initiated;
	}
}
